package com.edt.ichannel.api.service.impl;

import com.edt.ichannel.api.common.constant.CommonConstant;
import com.edt.ichannel.api.dao.AccountCompareDao;
import com.edt.ichannel.api.entiy.local.AccountCompare;
import com.edt.ichannel.api.service.AccountCompareService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 对账信息服务类
 * @author 孙梁
 */
@Service
public class AccountCompareServiceImpl implements AccountCompareService {
    private Logger logger = LogManager.getLogger(AccountCompareServiceImpl.class);
    @Resource
    private AccountCompareDao accountCompareDao;
    @Override
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public void saveAccountCompareList(List<AccountCompare> accountCompares) {
        if (accountCompares != null){
            int count = CommonConstant.BRANCH_COUNT;
            int lastIndex = count ;
            for(int index = 0; index < accountCompares.size();){
                if(lastIndex > accountCompares.size()){
                    lastIndex = accountCompares.size();
                    accountCompareDao.saveList(accountCompares.subList(index,lastIndex));
                    break;
                }else{
                    accountCompareDao.saveList(accountCompares.subList(index, lastIndex));
                    index = lastIndex;
                    lastIndex = index + (count);
                }
            }
            logger.info("list 长度："+accountCompares.size());
        }else{
            logger.info("list为空");
        }
    }
}
